//
//  FMDeniedAccessAlertTool.m
//  flutter_device_info_plugin
//
//  Created by 小琦 on 2025/3/2.
//

#import "FMDeniedAccessAlertTool.h"

@implementation FMDeniedAccessAlertTool

+ (void)showMessage:(nonnull NSString *)message {
    
    NSString *title = @"Access Denied";
    NSString *settings = @"Settings";
    NSString *cancel = @"Cancel";
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title
                                                                   message:message
                                                            preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *sAction = [UIAlertAction actionWithTitle:settings
                                                           style:UIAlertActionStyleDefault
                                                         handler:^(UIAlertAction * _Nonnull action) {
        NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        if ([[UIApplication sharedApplication] canOpenURL:url]) {
            [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
        }
    }];
    
    UIAlertAction *cAction = [UIAlertAction actionWithTitle:cancel
                                                           style:UIAlertActionStyleCancel
                                                         handler:nil];
    
    [alert addAction:sAction];
    [alert addAction:cAction];
    
    UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
    [rootViewController presentViewController:alert animated:YES completion:nil];
}

@end
